<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <meta name="robots" content="noindex, nofollow"/>
    <meta name="googlebot" content="noindex, nofollow"/>
    <title>登录-Online DDoS</title>

    <script type="text/javascript" src="" ></script>
    <link rel="stylesheet" type="text/css" href="main.css"/>

</head>
<body>
<div class="mask"></div>
<div class="container">
    <div class="login-wrapper">
        <svg id="peak" viewBox="0 0 1024 1024"><path fill="#FFF" d="M424 233.6L574.4 592c4.8 11.2 16 19.2 28.8 19.2h1.6c12.8 0 24-6.4 28.8-17.6l57.6-118.4 168 337.6H163.2l260.8-579.2m0-57.6c-6.4 0-11.2 3.2-14.4 9.6L113.6 846.4H912L704 433.6c-3.2-6.4-8-8-14.4-8-4.8 0-11.2 3.2-14.4 8l-73.6 147.2-163.2-395.2c-3.2-6.4-8-9.6-14.4-9.6z"></path></svg>
        <div class="form-control">
            <label>
                <input type="text" class="textfield" id="email" maxlength="32"/>
                <span class="emaillabel">邮箱地址</span>
            </label>
        </div>
        <div class="form-control">
            <label>
                <input type="password" class="textfield" id="password" maxlength="32"/>
                <span class="passwordlabel">密码</span>
            </label>
        </div>
        <br><br>
        <!-- <button>Login</button> -->
        <a href="#login" class="button" onclick="Login()">
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            登录
        </a>
        <a href="../register/index.html" class="button">
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            注册
        </a>
        <br><br><br><br><br>
        <a href="#findPassword" class="link">忘记密码?</a>
    </div>
</div>
<script type="application/javascript" src="main.js"></script>
</body>
<script type="text/javascript" src="md5.js"></script>
<script>
    function Login()
	{
        var email = document.getElementById("email").value;
        var password = document.getElementById("password").value;
		console.log("email=" + email+"&password="+hex_md5(password));
        if(email==""||password=="")
        {
            alert("请输入正确的邮箱地址和密码！");
            return;
        }
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var mes = trimStr(xmlhttp.responseText);
				if(mes == "error")
                {
                    alert("邮箱或密码错误!");
                }
                else if(mes == "no")
                {
                    alert("邮箱尚未注册！");
                }
                else if(mes == "success")
                {
                    alert("登录成功！");
					GetIDCode();
					window.location.href = "../index.html"
                }
				else
				{
					alert(mes);
				}
			}
		}
		var data = "email=" + email+"&password="+hex_md5(password);
		xmlhttp.open("POST", "../lib/login.jsp", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(data);
	}
    function trimStr(str) { 
        return str.replace(/(^\s*)|(\s*$)/g, ""); 
    }
	function GetIDCode()
	{
		var email = document.getElementById("email").value;
	    var id = hex_md5(document.getElementById("email").value);
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var mes = trimStr(xmlhttp.responseText);
				console.log(mes);
				setCookie("id",id,1);
				setCookie("code",mes,1);
				setCookie("email",email,1);
			}
		}
		var data = "id="+id;
		xmlhttp.open("POST", "../lib/checkid.jsp", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(data);
	}
	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date()
		exdate.setDate(exdate.getDate()+expiredays)
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/")
	}
</script>
</html>

